package com.yxym.try_;

public class TryCatchDetail02 {
    public static void main(String[] args) {
        try {
            Person person = new Person();
            //person = null;
            System.out.println(person.getName());//空指针异常
            int n1 = 10;
            int n2 = 0;
            int res = n1 /n2;//算术异常
            //1.try代码块可含有多个不同的异常
            //2.可以使用多个catch分别捕获不同的异常，相应处理
            //3.子类异常写在前面，父类异常写在后面
        } catch (NumberFormatException e){
            System.out.println("空指针异常：" + e.getMessage());
        }catch (ArithmeticException e){
            System.out.println("算数异常" + e.getMessage());
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            System.out.println("finally");
        }

    }
}
class Person{
    private String name;

    public String getName() {
        return name;
    }
}